import logo from '@/assets/image/logo.png';
import AvatarDef from '@/components/RightContent/AvatarDropdown';
import { LeftOutlined, PlusOutlined } from '@ant-design/icons';
import { history } from '@umijs/max';
import { Button } from 'antd';
import styles from './index.less';
// import React, { useEffect, useState } from 'react';

const LayoutHeader: React.FC<any> = (props: any) => {
  const { title, showDataBtn, showDocBtn, addNewDoc, knowledgeId } = props;

  const back = () => {
    console.log(history);
    if (history.location.pathname === '/main' || history.location.pathname === '/') {
      history.push('/');
    } else {
      history.back();
    }
    // history.push('/');
    // window.location.href = '/'
  };
  const addDoc = () => {
    // history.replace(`/conversation`);
    addNewDoc();
  };
  const dataDoc = () => {
    history.push(`/dataQuestion?kbid=${knowledgeId}`);
  };
  return (
    <div className={styles.containerCN}>
      {!title ? (
        <img
          src={logo}
          alt=""
          style={{ marginLeft: '22px', width: '84px', height: '14px' }}
          onClick={back}
        />
      ) : (
        <div className={styles.title} onClick={back}>
          <LeftOutlined /> {title}
        </div>
      )}
      <div className={styles.rightCon}>
        {showDocBtn && (
          <Button className={styles.dataBtn} icon={<PlusOutlined />} onClick={addDoc}>
            新建文档
          </Button>
        )}
        {showDataBtn && (
          <Button className={styles.dataBtn} onClick={dataDoc}>
            前往知识库
          </Button>
        )}
        <AvatarDef />
      </div>
    </div>
  );
};

export default LayoutHeader;
